package sgfapp.uno;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.Locale;

import org.json.JSONException;
import org.json.JSONObject;

import sgfapp.entities.Usuario;
import sgfapp.notificaciones.GcmHandler;
import sgfapp.secure.secureManager;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import com.facebook.*;
import com.facebook.android.Facebook;
import com.facebook.model.*;
import com.facebook.widget.LoginButton;
public class activity_start extends Activity{


	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_start);
		Log.e("GCMDemo","Arranca aplicacion");
    

		try
		{
			
			
			if(secureManager.login(this))
			{
				Log.e("GCMDemo","activity_start logueado");
				//Usuario.CargarUsuario(getBaseContext());
		        ProgressDialog pDialog = new ProgressDialog(this);
		        //pDialog.setMessage("Cargando..");
		        //pDialog.setIndeterminate(true);
		        //pDialog.setCancelable(true);
		        //pDialog.show();
				Usuario.CargarUsuario(this,pDialog);
				
				//secureManager.getUsuario(this);
				Log.e("activity_start GCMDemo","abierta start");
		    	Intent intent = new Intent(this, activity_menu.class);
		        startActivity(intent);
		        Log.e("activity_start GCMDemo","abierta 2");
			}
			else
			{
				Log.e("activity_start GCMDemo","cerrada start");
		    	Intent intent = new Intent(this, MainActivity.class);
		        startActivity(intent);
		        Log.e("activity_start GCMDemo","cerrada 2");
				
			}
		}
		catch(Exception e)
		{
			Log.e("activity_start GCMDemo","salio por el catch: "+e.toString());
	    	Intent intent = new Intent(this, MainActivity.class);
	        startActivity(intent);
		}
		
		finish();
	}
	

	
	  @Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		finish();
	}



	@Override
	  public void onActivityResult(int requestCode, int resultCode, Intent data) {
	      super.onActivityResult(requestCode, resultCode, data);
	      Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);

	  }
	

}
